"""
内容:通过首页点击手机类型模块进入选择商品,通过赛选手机颜色进入商品详情页面
作者:刘芳
"""
# 引入模块
from common.base import Base, create_browser_op
import time


# 创建类
class PageGotoPhone(Base):
    # 定义属性
    url = "http://localhost:8080/ecshop/index.php"
    phone = ("xpath","//a[@href='category.php?id=1']")
    color=("xpath","//div[@class='guige']/div[4]/a[3]")
    goods =("xpath","//img[@src='images/200905/thumb_img/32_thumb_G_1242110760196.jpg']")
    text = "label[for='spec_value_163']"

    # 定义方法
    # 打开网页
    def page_goto_phone_type_open_web(self):
        self.base_open_web(self.url)

    # 点击手机类型
    def page_goto_phone_type_click(self):
        self.base_click(self.phone)

    #点击 颜色分类,黑色
    def page_goto_phone_type_color_click(self):
        self.base_click(self.color)

    # 点击商品
    def page_goto_phone_type_goods_click(self):
        self.base_click(self.goods)

    # 获取颜色文本
    def page_goto_phone_type_text(self):
        return self.base_get_text1(self.text)

    # 退出
    def page_goto_phone_type_quit(self):
        self.base_quit()

    # 查看源代码
    def page_goto_phone_type_get_attribute(self):
        result = self.base_get_attribute(self.text)
        return result


if __name__ == '__main__':
    pg1 = PageGotoPhone(create_browser_op(r'C:\Users\86184\AppData\Local\Google\Chrome\User Data'))
    pg1.page_goto_phone_type_open_web()
    pg1.page_goto_phone_type_click()
    pg1.page_goto_phone_type_color_click()
    pg1.page_goto_phone_type_goods_click()
    print(pg1.page_goto_phone_type_text())
    # print(pg1.page_goto_phone_type_get_attribute())
    pg1.page_goto_phone_type_quit()